package com.atguigu.ossservice.controller;

import com.atguigu.commonutils.R;
import com.atguigu.ossservice.service.FileService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Auther 赵乾坤
 * @Date 2021-06-30 21:56
 * 要开启nginx 因为config.dev.env.js 他base_api是8001 他就会走 8001，不走8002vue
 * location ~ /eduoss/ {
 * proxy_pass http://localhost:8001;
 * }
 * --------------开发可以用nginxwindos版，测试生产要用 linux
 */
@RestController
@RequestMapping("/eduoss/ossfile")
@CrossOrigin
@Api(description = "文件上传类")
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping(value = "uploadFile")
    @ApiOperation("上传文件")
    @ApiOperationSupport(author = "zqk", order = 1)
    public R uploadFile(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestParam("file") MultipartFile file) {
        //1.获取要上传的文件
        //2.调用接口上传文件，获取url
        String url = fileService.uploadFileOSS(file);
        return R.ok().message("文件上传成功").data("url", url);
    }

}






